package com.situ.web.service.impl;

import com.situ.web.dao.ITeacherDao;
import com.situ.web.dao.impl.TeacherDaoImpl;
import com.situ.web.pojo.Teacher;
import com.situ.web.pojo.query.TeacherQuery;
import com.situ.web.service.ITeacherService;
import com.situ.web.util.PageResult;

import java.util.List;

public class TeacherServiceImpl implements ITeacherService {
    private ITeacherDao teacherDao = new TeacherDaoImpl();

    @Override
    public PageResult<Teacher> selectByPage(TeacherQuery teacherQuery) {
        List<Teacher> list = teacherDao.selectByPage(teacherQuery);
        Integer totalCount = teacherDao.selectTotalCount(teacherQuery);

        PageResult<Teacher> pageResult =  new PageResult<>(0, "", totalCount, list);
        return pageResult;
    }

    @Override
    public void deleteById(int id) {
        teacherDao.deleteById(id);
    }

    @Override
    public void add(Teacher teacher) {
        teacherDao.add(teacher);
    }

    @Override
    public Teacher selectById(int id) {
        return teacherDao.selectById(id);
    }

    @Override
    public void update(Teacher teacher) {
        teacherDao.update(teacher);
    }

    @Override
    public void deleteAll(String[] ids) {
        for (String id : ids) {
            teacherDao.deleteById(Integer.parseInt(id));
        }
    }
}